//
//  TravelCell.m
//  MyTrip
//
//  Created by zhang on 15/8/23.
//  Copyright (c) 2015年 张益. All rights reserved.
//

#import "TravelCell.h"
#import "UIImageView+WebCache.h"
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width

@implementation TravelCell

- (void)dealloc
{
    [_viewLabel release];
    [_viewImage release];
    [_replyLabel release];
    [_replyImage release];
    [_authorLabel release];
    [_titleLabel release];
    [_travelImage release];
    [super dealloc];
}
- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.travelImage = [[[UIImageView alloc] initWithFrame:CGRectMake(5 * OffWidth, 5 * OffHeight, 130 * OffWidth, 90 * OffHeight)] autorelease];
        [self.contentView addSubview:_travelImage];
        
        self.titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5 * OffWidth + _travelImage.frame.size.width + 10 * OffWidth, 5 * OffHeight, ScreenWidth - 10 * OffWidth - 20 * OffWidth - _travelImage.frame.size.width, 45 * OffHeight)] autorelease];
        [self.contentView addSubview:_titleLabel];
        
        self.authorLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5 * OffWidth + _travelImage.frame.size.width + 10 * OffWidth, _titleLabel.frame.size.height + _titleLabel.frame.origin.y, 100 * OffWidth, 25 * OffHeight)] autorelease];
        [self.contentView addSubview:_authorLabel];
        
        self.viewImage = [[[UIImageView alloc] initWithFrame:CGRectMake(5 * OffWidth + _travelImage.frame.size.width + 10 * OffWidth, _authorLabel.frame.size.height + _authorLabel.frame.origin.y, 18 * OffWidth, 15 * OffHeight)] autorelease];
        [self.contentView addSubview:_viewImage];
        
        self.viewLabel = [[[UILabel alloc] initWithFrame:CGRectMake(_viewImage.frame.size.width + _viewImage.frame.origin.x + 3 * OffWidth, _authorLabel.frame.size.height + _authorLabel.frame.origin.y, 40 * OffWidth, 20 * OffHeight)] autorelease];
        [self.contentView addSubview:_viewLabel];
        
        self.replyImage = [[[UIImageView alloc] initWithFrame:CGRectMake(_viewLabel.frame.size.width + _viewLabel.frame.origin.x + 5 * OffWidth, _authorLabel.frame.size.height + _authorLabel.frame.origin.y, 18 * OffWidth, 15 * OffHeight)] autorelease];
        [self.contentView addSubview:_replyImage];
        
        self.replyLabel = [[UILabel alloc] initWithFrame:CGRectMake(_replyImage.frame.size.width + _replyImage.frame.origin.x + 3 * OffWidth, _authorLabel.frame.size.height + _authorLabel.frame.origin.y, 40 * OffWidth, 20 * OffHeight)];
        [self.contentView addSubview:_replyLabel];
        
    }
    return  self;

}


- (void)setValueWithDic:(NSDictionary *)dic{
    
    [_travelImage sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"photo"]] placeholderImage:nil];
    [_titleLabel setText:[dic objectForKey:@"title"]];
    [_titleLabel setNumberOfLines:2];
    [_titleLabel setFont:[UIFont systemFontOfSize:14]];
    [_authorLabel setText:[dic objectForKey:@"username"]];
    [_authorLabel setAlpha:0.5];
    [_authorLabel setFont:[UIFont systemFontOfSize:13]];
    _viewImage.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"view" ofType:@"png"]];
    [_viewLabel setText:[NSString stringWithFormat:@"%@", [dic objectForKey:@"views"]]];
    [_viewLabel setFont:[UIFont systemFontOfSize:13]];
    [_viewLabel setAlpha:0.5];
    [_replyImage setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"reply" ofType:@"png"]]];
    [_replyLabel setText:[NSString stringWithFormat:@"%@", [dic objectForKey:@"replys"]]];
    [_replyLabel setFont:[UIFont systemFontOfSize:13]];
    [_replyLabel setAlpha:0.5];
}










- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
